#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;

const int kMaxN = 1200;
const int kMaxM = 1e5 + 10;

unordered_map<string, int> dict;
int num[kMaxM];
int cnt[kMaxN];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;

    cin >> s;
    dict[s] = i + 1;
  }
  int m, ans_n = 0;

  cin >> m;
  for (int i = 0; i < m; i++) {
    string s;

    cin >> s;
    if (dict.find(s) != dict.end()) {
      num[i] = dict[s];
      if (cnt[num[i]] == 0) {
        cnt[num[i]]++;
        ans_n++;
      }
    } else {
      num[i] = 0;
    }
  }

  fill(cnt, cnt + n + 1, 0);
  int ans = kMaxM;
  int tot = 0;
  for (int i = 0, j = 0; i < m; i++) {
    for (; j < m; j++) {
      if (tot >= ans_n) {
        break;
      }
      cnt[num[j]]++;
      if (cnt[num[j]] == 1 && num[j] > 0) {
        tot++;
      }
    }
    if (tot >= ans_n) {
      ans = min(ans, j - i);
    }
    cnt[num[i]]--;
    if (cnt[num[i]] == 0 && num[i] > 0) {
      tot--;
    }
  }
  cout << ans_n << "\n"
       << max(0, ans) << "\n";
  return 0;
}